function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
  		// code for IE7+, Firefox, Chrome, Opera, Safari
  		return new XMLHttpRequest();
  	}
	if (window.ActiveXObject) {
  		// code for IE6, IE5
  		return new ActiveXObject("Microsoft.XMLHTTP");
  	}
	alert ("Your browser does not support XMLHTTP!");
	return null;
}

function ajaxDonHang(maHang, linkAmin) {
	xmlhttp=GetXmlHttpObject();
  	var  data = "maHang=" + maHang;
	var url="index.php?m=home&a=ajaxDonHang"+linkAmin;
	xmlhttp.onreadystatechange=function ()
	{
		if (xmlhttp.readyState==4)
		{
			var myData= xmlhttp.responseText;
			document.getElementById(maHang).innerHTML = myData;
		}
	}
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(data);
}

function ajaxActive(maHang, linkAmin) {
	xmlhttp=GetXmlHttpObject();
  	var  data = "maHang=" + maHang;
	var url="index.php?m=home&a=ajaxActive"+linkAmin;
	xmlhttp.onreadystatechange=function ()
	{
		if (xmlhttp.readyState==4)
		{
			var myData= xmlhttp.responseText;
			if(myData == 1){
				document.getElementById(maHang+"_a").style.display = "none";
				document.getElementById(maHang+"_d").innerHTML = "<img style='opacity:0.3;' src='images/default/b_usrdrop.png'>";
			}
		}
	}
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(data);
}

function resetPass(id, linkAmin) {
	xmlhttp=GetXmlHttpObject();
  	var  data = "id=" + id;
	var url="index.php?m=user&a=resetPass"+linkAmin;
	xmlhttp.onreadystatechange=function ()
	{
		if (xmlhttp.readyState==4)
		{
			var myData= xmlhttp.responseText;
			if(myData == 1){
				document.getElementById("resetPass_"+id).innerHTML = "<img src='images/default/camxuc2.gif'>";
			} else {
				document.getElementById("resetPass_"+id).innerHTML = "<img src='images/default/camxuc.gif'>";
			}
		}
	}
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(data);
}

/* function use submit form */
function frmSubmit(url, itemID, mode, type) {
	document.form1.action = "index.php?" + url;
	document.form1['itemID'].value = itemID;
	document.form1['mode'].value = mode;
	document.form1['type'].value = type;
	document.form1.submit();
}

function hrefLocation(url, value, token) {
	window.location.href = url+value+token;
}

function checkAll() {
	var rows = document.getElementsByTagName('input');
	for ( var i in rows) {
		if (rows[i].type == 'checkbox') {
			rows[i].checked = true;
		}
	}
}

function uncheckAll() {
	var rows = document.getElementsByTagName('input');
	for ( var i in rows) {
		if (rows[i].type == 'checkbox') {
			rows[i].checked = false;
		}
	}
}

function checkInputText(id_form) {
	var rows = document.getElementById(id_form).getElementsByTagName('input');
	var j = 0;
	for (var i in rows) {
		if (rows[i].type == 'text' && rows[i].value == '') {
			rows[i].style.background = '#FFAAAA';
			j++;
		}
	}
	if (j == 0){
		return true;
	} else {
		return false;
	}
}

function checkFormRegister() {
	var arID = new Array('hoten', 'diachi', 'phone', 'email', 'nickname', 'pass', 'txtRePassword');
	var j = 0;
	for (var i in arID) {
		var v = document.getElementById(arID[i]);
		if (v.value == '') {
			v.style.background = '#FFAAAA';
			j++;
		} else {
			v.style.background = '#FFFFFF';
		}
	}
	if (j > 0) {
		return false;
	} else {
		return true;
	}
}

function checkFormForget() {
	var arID = new Array('email', 'captcha');
	var j = 0;
	for (var i in arID) {
		var v = document.getElementById(arID[i]);
		if (v.value == '') {
			v.style.background = '#FFAAAA';
			j++;
		} else {
			v.style.background = '#FFFFFF';
		}
	}
	if (j > 0) {
		return false;
	} else {
		return true;
	}
}

function checkFormLogin() {
	var arID = new Array('nickname', 'password');
	var j = 0;
	for (var i in arID) {
		var v = document.getElementById(arID[i]);
		if (v.value == '') {
			v.style.background = '#FFAAAA';
			j++;
		} else {
			v.style.background = '#FFFFFF';
		}
	}
	if (j > 0) {
		return false;
	} else {
		return true;
	}
}

function checkFormContact() {
	var arID = new Array('hoten', 'email', 'noidung', 'captcha');
	var j = 0;
	for (var i in arID) {
		var v = document.getElementById(arID[i]);
		if (v.value == '') {
			v.style.background = '#FFAAAA';
			j++;
		} else {
			v.style.background = '#FFFFFF';
		}
	}
	if (j > 0) {
		return false;
	} else {
		return true;
	}
}

function checkFormSendMail() {
	var arID = new Array('tieude', 'captcha');
	var j = 0;
	for (var i in arID) {
		var v = document.getElementById(arID[i]);
		if (v.value == '') {
			v.style.background = '#FFAAAA';
			j++;
		} else {
			v.style.background = '#FFFFFF';
		}
	}
	if (j > 0) {
		return false;
	} else {
		return true;
	}
}

function checkFormEcode() {
	var arID = new Array('passOld', 'passNew', 'passNew2');
	var j = 0;
	for (var i in arID) {
		var v = document.getElementById(arID[i]);
		if (v.value == '') {
			v.style.background = '#FFAAAA';
			j++;
		} else {
			v.style.background = '#FFFFFF';
		}
	}
	if (j > 0) {
		return false;
	} else {
		return true;
	}
}

function uncheckInputText(id) {
	var rows = document.getElementById(id);
	rows.style.background = '#FFFFFF';
}

function cfdelete() {
	var x = confirm('Bạn thật sự muốn xóa mục này!!');
	if (x) {
		return true;
	} else {
		return false;
	}
}

function comfornActive() {
	var x = confirm('Bạn chắc chắn đã thu tiền hóa đơn này !!');
	if (x) {
		return true;
	} else {
		return false;
	}
}

function comfornResetPass() {
	var x = confirm('Xác nhận reset lại mật khẩu này !!');
	if (x) {
		return true;
	} else {
		return false;
	}
}

function checkKhuyenMai() {
	var valc = document.getElementById('check_km');
	var valt = document.getElementById('giakhuyenmai');
	if (valc.checked) {
		valt.style.display = 'block';
	} else {
		valt.style.display = 'none';
	}
}

function buttonhide() {
	var chk = document.getElementById('chkShow');
	var chkB = document.getElementById('btdangky');
	if (chk.checked) {
		chkB.disabled = '';
	} else {
		chkB.disabled = 'disabled';
	}
}

function messageError() {
	alert('Số hàng trong kho đã hết, bạn vui lòng chọn sản phẩm khác thay thế !');
}

